package com.example;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

/**
 * Created by Administrator on 2018/5/16.
 */

public class PhoneResult extends AppCompatActivity {
    private String phnumer;
    private TextView phone;
    private TextView result;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.phoneresult);
        getPhonenumber();
        initView();
        initResult();
    }

    private void initView() {
        phone = findViewById(R.id.result);
        result = findViewById(R.id.tv_view);
    }

    private void getPhonenumber() {
        Intent intent = getIntent();
        if (intent != null) {
            Bundle bundle = intent.getExtras();
            if (bundle.containsKey("number")) {
                phnumer = bundle.getString("number");
            }
        }
    }

    private void initResult() {
        phone.setText("您要查询的电话号码：" + phnumer);
        if (phnumer.startsWith("180")) {
            result.setText("北京");
        } else if (phnumer.startsWith("150")) {
            result.setText("天津");
        } else {
            result.setText("未知地区");
        }
    }
}
